/**
 * @author shahma
 */
dojo.provide("medryx.orm.Property");
dojo.require("medryx.orm.internal.ManagedProperty");

/**
 *  ARGUMENTS:
 *  readOnly:TRUE | false //if false, then automatic dirty checking is performed on this property. if false, then no dirty checking occurs and no setter is built
 *  converter:object that implements medryx.orm.Converter|string name of object that can be dojo.required 
 *  lazy: TRUE | false //if false then if this property is not initialized at object creation time, it is fetched immediately. o
 * 			  otherwise, it is only fetched when a call to the property's accessor is made
 *  label:integer: if > 0, then this is used for a label. appended to the label in order 
 *  array:FALSE | true : accept an array as a value (NOT A COLLECTION OF ASSOCIATION, AN ARRAY OF SIMPLE)
 */
dojo.declare("medryx.orm.Property", medryx.orm.internal.ManagedProperty, {
	constructor:function() {
		if (!this.converter) {
            this.converter = this.passthroughConverter;
        }
		if (typeof this.lazy === "undefined") {
			this.lazy = true;
		}
		if (typeof this.readOnly === "undefined") {
            this.readOnly = true;
        }
	},
	
	isArray:function() {
		return this.array ? true : false;
	},
	
	isLabel:function() {
		return this.label ? true : false;
	},
	
	passthroughConverter:{
		fromPropertyToString:function(value) {
			return value;
		},
		fromStringToProperty:function(strValue) {
			return strValue;
		}
	},
    initialize:function(instance, propertyName, value) {
		if (typeof value === "undefined") {
			value = this;
		} else {
			value = this.converter.fromStringToProperty(value);
		}
		this.set(instance, propertyName, value);
		return instance[propertyName];
	}
});